package com.xmlstrategys
{
	import com.Global;
	import com.strategy.IXML;
	import com.utils.Utils;
	
	import flash.utils.ByteArray;
	
	import mx.graphics.codec.JPEGEncoder;
	
	public class XMLTaskInfo extends XMLBase implements IXML
	{
		public function XMLTaskInfo(data:XML)
		{
			super(data);
		}
		
		public function xmlstrategybml():ByteArray
		{
			var sourceByte:ByteArray = Utils.writeHead(8);
			var nodeLen:uint = xmlData.tasks.length();
			sourceByte.writeUnsignedInt(nodeLen);
			
			var num:int = 0;
			for each (var xml:XML in xmlData.tasks)
			{
				
				sourceByte.writeUnsignedInt(xml.@taskId);
				Utils.writeString(xml.@title,sourceByte);
				Utils.writeString(xml.@objectives,sourceByte);
				Utils.writeString(xml.@taskDes,sourceByte);
				Utils.writeString(xml.@taskProcessFinish,sourceByte);
				Utils.writeString(xml.@taskFinish,sourceByte);
				Utils.writeString(xml.@taskUnFinish,sourceByte);
				
				
				
				sourceByte.writeUnsignedInt(xml.@taskType);
				sourceByte.writeUnsignedInt(xml.@flags);
				sourceByte.writeUnsignedInt(xml.@quality);
				sourceByte.writeUnsignedInt(xml.@taskNpcId);

				
				Utils.writeString(xml.@taskNPC,sourceByte);
				sourceByte.writeUnsignedInt(xml.@taskCommitNpcId);
				Utils.writeString(xml.@taskCommitNPC,sourceByte);
				Utils.writeString(xml.@taskNPCAndPoint,sourceByte);
				
				sourceByte.writeUnsignedInt(xml.@minLevel);
				sourceByte.writeUnsignedInt(xml.@maxLevel);
				sourceByte.writeUnsignedInt(xml.@requireJob);
				sourceByte.writeUnsignedInt(xml.@limitTime);
				sourceByte.writeUnsignedInt(xml.@preTaskId);
				sourceByte.writeUnsignedInt(xml.@nextTaskId);
				sourceByte.writeUnsignedInt(xml.@rewardGold);
				sourceByte.writeUnsignedInt(xml.@rewardExp);
				
				var index:int = 0;
				
				Utils.xmlToArray(xml.@questItemReward,sourceByte);
				
				
				Utils.xmlToArray(xml.@itemRewardOptional,sourceByte);
				Utils.xmlToArray(xml.@prestige,sourceByte);
				
				sourceByte.writeUnsignedInt(xml.@rewardBuffId);
				
				Utils.xmlToArray(xml.@receiveGold,sourceByte);
				
				var valueT:Array = (Global.FlagBit[num]).toString().split("_");
				while (index < 1)
				{
					
					sourceByte.writeUnsignedInt(valueT[0]);
					sourceByte.writeUnsignedInt(valueT[1]);
					index++;
				}
				index = 0;
				
				sourceByte.writeUnsignedInt(xml.@requiredGold);
				
				Utils.xmlToArray(xml.@questCondition,sourceByte,true);
				
				sourceByte.writeUnsignedInt(xml.@dailyTotalCnt);
				num++;
			}
			
			return sourceByte;
		}
		
		/**
		 * 写入. 
		 * @param obj
		 * @param ba
		 * 
		 */		
		private function writeElement(obj:*,ba:ByteArray):void
		{
			/**
			 * 
				
				while(index<3)
				{
					sourceByte.writeUnsignedInt(xml.questItemReward.@["itemID"+index]);
					sourceByte.writeUnsignedInt(xml.questItemReward.@["count"+index]);
					index++;
				}
				index = 0;
				
				while (index < 5)
				{
					sourceByte.writeUnsignedInt(xml.itemRewardOptional.@["itemID"+index]);
					sourceByte.writeUnsignedInt(xml.itemRewardOptional.@["count"+index]);
					index++;
				}
				
				index = 0;
				
				while (index < 2)
				{
					sourceByte.writeUnsignedInt(xml.prestige.@["flag"+index]);
					sourceByte.writeUnsignedInt(xml.prestige.@["reward"+index]);
					index++;
				}
				
				index = 0;
				
				sourceByte.writeUnsignedInt(xml.@rewardBuffId);
				
				
				while (index < 2)
				{
					sourceByte.writeUnsignedInt(xml.receiveGold.@["flag"+index]);
					sourceByte.writeUnsignedInt(xml.receiveGold.@["gold"+index]);
					index++;
				}

				index = 0;

				var valueT:Array = (Global.FlagBit[num]).toString().split("_");
				while (index < 1)
				{
					
					sourceByte.writeUnsignedInt(valueT[0]);
					sourceByte.writeUnsignedInt(valueT[1]);
					index++;
				}
				index = 0;
				
				sourceByte.writeUnsignedInt(xml.@requiredGold);
				
				while (index < 3)
				{
					sourceByte.writeUnsignedInt(xml.questCondition.@["type"+index]);
					sourceByte.writeUnsignedInt(xml.questCondition.@["parm1"+index]);
					sourceByte.writeUnsignedInt(xml.questCondition.@["target"+index]);
					Utils.writeString(xml.questCondition.@["desc"+index],sourceByte);
					index++;
				}
				index = 0;
				sourceByte.writeUnsignedInt(xml.@dailyTotalCnt);
			 * */
		}
		
		
		
		
		
	}
}